package com.ktwlsoft.fundmanage.domain.repository;

import com.ktwlsoft.fundmanage.domain.entity.TransferApply;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface TransferApplyRepository extends JpaRepository<TransferApply, Long> {

    @Modifying
    @Query("update TransferApply t set t.receiver = :payee, t.receiverBankCardNum=:idCard, t.receiverBankName=:bank, t.receiverBankCardNum=:bankAccount where t.id=:id")
    int setOtehrReceiver(long id, String payee, String idCard, String bank, String bankAccount);

    /**
      * 根据tscode查询数据 on 2019/9/20 14:23
      * @param tsCode tsCode
      * @return List<TransferApply>
      */
    List<TransferApply> findByTsCode(Long tsCode);

    List<TransferApply> findByFundInCode(long fCode);

    List<TransferApply> findByOperatorIdAndState(String operatorId, TransferApply.State state);

    List<TransferApply> findByApprovalFlowAndState(long approvalFlow, TransferApply.State state);

    boolean existsByTransferTypeAndApprovalFlow(TransferApply.TransferType transferType, Long approvalFlow);

    boolean existsByStateAndTsCode(TransferApply.State normal, Long tsCode);

    boolean existsByTsCodeAndFundInCodeAndState(Long tsCode, long fCode, TransferApply.State normal);
}
